package org.linlinjava.litemall.wx.web;

import javax.validation.constraints.NotNull;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.WxReceiptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 我的收据、校验单
 */
@RestController
@RequestMapping("/wx/receipt")
@Validated
public class WxReceiptController {
	private final Log logger = LogFactory.getLog(WxReceiptController.class);

	@Autowired
	private WxReceiptService wxReceiptService;

	@GetMapping("list")
	public Object list(@LoginUser Integer userId, @NotNull Byte type, @RequestParam(defaultValue = "1") Integer page,
			@RequestParam(defaultValue = "10") Integer limit,
			@Sort @RequestParam(defaultValue = "add_time") String sort,
			@Order @RequestParam(defaultValue = "desc") String order,
			@RequestParam(defaultValue = "") String searchValue) {

		return wxReceiptService.list(userId, type, page, limit, sort, order, searchValue);
	}

	@GetMapping("detail")
	public Object detail(@LoginUser Integer userId, @NotNull Integer id, @NotNull Integer itemId) {
		if (userId == null) {
			return ResponseUtil.unlogin();
		}
		return wxReceiptService.detail(userId, id, itemId);
	}
}